#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int
main(int argc, char* args[])
{
	if(argc != 2){
		perror("arg error");
		exit(1);
	}

	int fd3 = open(args[1], O_RDWR | O_CREAT, 0744);
	if(fd3 < 0){
		perror("open error");
		exit(1);
	}
	printf("fd3 = %d\n", fd3);


	int fd4 = open(args[1], O_RDWR | O_CREAT, 0744);
	if(fd4 < 0){
		perror("open error");
		exit(1);
	}
	printf("fd4 = %d\n", fd4);

	int fd5 = open(args[1], O_RDWR | O_CREAT, 0744);
	if(fd5 < 0){
		perror("open error");
		exit(1);
	}
	printf("fd5 = %d\n", fd5);

	close(fd3);
	close(fd4);


	int newfd5;
	newfd5 = fcntl(newfd5, F_DUPFD, 5);
	if(newfd5 < 0){
		perror("fcntl dup error");
		exit(1);
	}
	printf("newfd5 = %d\n", newfd5);

	write(fd3, "fd3", 3);
	write(newfd5, "newfd5", 6);

	exit(0);
}
